package ar.com.fiuba.ElectronicCircuitAnalyst.domain.impl;

import java.util.ArrayList;
import java.util.List;

import ar.com.fiuba.ElectronicCircuitAnalyst.domain.api.Connection;
import ar.com.fiuba.ElectronicCircuitAnalyst.domain.api.Lead;
import ar.com.fiuba.ElectronicCircuitAnalyst.domain.common.Specification;
import ar.com.fiuba.ElectronicCircuitAnalyst.domain.exceptions.LeadConnectionLimitReachedException;

public class LeadImpl implements Lead {

	private Boolean value;
	private List<Connection> connections;
	private Specification<Lead> connectionLimitSpecification;

	public LeadImpl(Boolean value, Specification<Lead> connectionLimitSpec) {
		this.value = value;
		this.connectionLimitSpecification = connectionLimitSpec;
		connections = new ArrayList<Connection>();
	}

	public LeadImpl(Specification<Lead> connectionLimitSpec) {
		this(false, connectionLimitSpec);
	}

	public Boolean isConnected() {
		return (this.connections.size() != 0);
	}

	public void addConnection(Connection connection) throws LeadConnectionLimitReachedException {
		if (!this.connectionLimitSpecification.isSatisfiedBy(this)) {
			throw new LeadConnectionLimitReachedException("Connection limit reached for this Lead");
		}
		this.connections.add(connection);
	}

	public Boolean getValue() {
		return value;
	}

	public void setValue(Boolean value) {
		this.value = value;
	}

	public List<Connection> getConnections() {
		return this.connections;
	}

}
